package com.happyfamily.springboot.crowdsourcingplatform.controller.weng;

import com.happyfamily.springboot.crowdsourcingplatform.service.weng.TotalService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/api-back/total")
@Slf4j
public class TotalController
{
	@Autowired
	TotalService totalService;

	@GetMapping("/getNeedNumber")
	@ResponseBody
	@ApiOperation(value = "统计需求数", notes = "统计需求数", httpMethod = "GET", response = int.class)
	public int getNeedNumber()
	{
		return totalService.getNeedNumber();
	}

	@GetMapping("/getWorkNumber")
	@ResponseBody
	@ApiOperation(value = "统计作品数", notes = "统计作品数", httpMethod = "GET", response = int.class)
	public int getWorkNumber()
	{
		return totalService.getWorkNumber();
	}

	@GetMapping("/getOrderNumber")
	@ResponseBody
	@ApiOperation(value = "统计订单数", notes = "统计订单数", httpMethod = "GET", response = int.class)
	public int getOrderNumber()
	{
		return totalService.getOrderNumber();
	}

	@GetMapping("/getTenderNumber")
	@ResponseBody
	@ApiOperation(value = "统计投标数", notes = "统计投标数", httpMethod = "GET", response = int.class)
	public int getTenderNumber()
	{
		return totalService.getTenderNumber();
	}

	@GetMapping("/getFriendNumber")
	@ResponseBody
	@ApiOperation(value = "统计友情链接数", notes = "统计友情链接数", httpMethod = "GET", response = int.class)
	public int getFriendNumber()
	{
		return totalService.getFriendNumber();
	}

	@GetMapping("/getExposureNumber")
	@ResponseBody
	@ApiOperation(value = "统计需求数", notes = "统计需求数", httpMethod = "GET", response = int.class)
	public int getExposureNumber()
	{
		return totalService.getExposureNumber();
	}


	@GetMapping("/pswChange")
	public String pswChange(HttpServletRequest request, Model model)
	{
		SecurityContextImpl securityContext = (SecurityContextImpl) request.getSession().getAttribute("SPRING_SECURITY_CONTEXT");
		String account = securityContext.getAuthentication().getName();
		model.addAttribute("account", account);
		return "backPage/psw-change";
	}
}
